package com.woniuxy.microuserserver.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.microcommonserver.bean.user_hpd.UserInfo;
import com.woniuxy.microcommonserver.pageHelper.PageRequest;
import com.woniuxy.microuserserver.mapper.UserInfoMapper;
import com.woniuxy.microuserserver.service.IUserInfoService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

@Service
@Transactional(readOnly = true)
public class UserInfoServiceImpl implements IUserInfoService {
    @Resource
    private UserInfoMapper userInfoMapper;

    @Override
    public PageInfo<UserInfo> findAllByParams(PageRequest request, UserInfo userInfo) {
        return PageHelper.startPage(request.getPageNum(),request.getLimit()).
                doSelectPageInfo(()->userInfoMapper.findAllByParams(request,userInfo));
    }

    @Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
    @Override
    public int addUser(UserInfo userInfo) {
        return userInfoMapper.addUser(userInfo);
    }

    @Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
    @Override
    public int updateUser(UserInfo userInfo) {
        return userInfoMapper.updateUser(userInfo);
    }

    @Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
    @Override
    public int deleteUser(Long id) {
        return userInfoMapper.deleteUser(id);
    }

    @Override
    public UserInfo findOneById(Long id) {
        return userInfoMapper.findOneById(id);
    }
}
